home *** CD-ROM | disk | FTP | other *** search
/ Packard Bell - Internet on a CD / internet on a cd.cdr / Internet / sites / Clementine_NASA / image.hqx / Image folder / Macros / Input_Output Macros < prev    next >
Encoding:
Text File  |  1991-07-19  |  3.4 KB  |  135 lines

  1. macro 'Save using Time as Name';
  2. {Note: Colons are not allowed in file names.}
  3. var
  4.   year,month,day,hour,minute,second,DayOfWeek:integer;
  5. begin
  6.   GetTime(year,month,day,hour,minute,second,DayOfWeek);
  7.   SaveAs(year-1900:2,'-',month:2,'-',day:2,
  8.          '/',hour:2,'-'minute:2,'-',second:2);
  9. end;
  10.  
  11.  
  12. macro 'Open with selection [O]';
  13. begin
  14.   if nPics>0 then KillRoi; {Save Selection}
  15.   Open('');                {Prompt for file name}
  16.   RestoreROI;              {Transfer selection to new window}
  17. end;
  18.  
  19.  
  20. macro 'Save All';
  21. {
  22. Saves all currently open images in a folder using '0001', '0002', etc.
  23. as the file names. The save file dialog box will be displayed once
  24. so that you can specify the folder to save the files in.
  25. }
  26. var
  27.   n:integer;
  28. begin
  29.   for n:=1 to nPics do begin
  30.     SelectPic(n);
  31.     SetPicName(n:2);
  32.     SaveAs;
  33.     {Export;}
  34.   end;
  35. end;
  36.  
  37.  
  38. macro 'Import FITS';
  39. {
  40. This is an example of how to decode an image file header. In this case, the header is 2880 bytes long and bytes 266-269 contain the width(ASCII) and bytes
  41. 246-249 cantain the height. Refer to "FITS:A Flexible Image Transport System",
  42. Astronomy and Astrophysics Supplement Series 44, 1981, 363-370.
  43. }
  44. var
  45.   width,height,offset,i,d,m:integer;
  46. begin
  47.   width:=512; 
  48.   height:=1;
  49.   offset:=0;
  50.   SetImport('8-bit'); 
  51.   SetCustom(width,height,offset);
  52.   Import(''); {Read in header as an image, prompting for the file name.}
  53.   if not ((GetPixel(108,0)=49) and (GetPixel(109,0)=54)) then begin
  54.     {BITPIX<>16}
  55.     PutMessage('This macro only reads 16-bit FITS files');
  56.     Dispose(nPics);
  57.     exit;
  58.   end;
  59.   m:=1000;
  60.   width:=0;
  61.   for i:=266 to 269 do begin
  62.     d:=GetPixel(i,0);
  63.     if d=32 then d:=48;
  64.     d:=d-48;
  65.     width:=width+d*m;
  66.     m:=m/10;
  67.   end;
  68.   m:=1000;
  69.   height:=0;
  70.   for i:=346 to 349 do begin
  71.     d:=GetPixel(i,0);
  72.     if d=32 then d:=48;
  73.     d:=d-48;
  74.     height:=height+d*m;
  75.     m:=m/10;
  76.   end;
  77.   Dispose(nPics);  {The ID of the last window opened is equal to nPics.}
  78.   offset:=2880;
  79.   SetImport('16-bit Signed; Calibrate; Autoscale');
  80.   SetCustom(width,height,offset);
  81.   Import('');  {No prompt this time; Import remembers the name.}
  82.   FlipVertical;
  83. end;
  84.  
  85.  
  86. macro 'Import Image TIFF File';
  87. {
  88. As an example of how to import a foreign file format, this macro reads
  89. the TIFF files created by Image. The format of an Image TIFF file
  90. is described in Appendix E of the Image manual.
  91. }  
  92. var
  93.   width,height,offset:integer;
  94. begin
  95.   width:=768; 
  96.   height:=1;
  97.   offset:=0;
  98.   SetImport('8-bit'); 
  99.   SetCustom(width,height,offset);
  100.   Import(''); {Read in header as an image, prompting for the file name.}
  101.   if not ((GetPixel(0,0)=77) and (GetPixel(0,0)=77)) then begin  {'MM'}
  102.     PutMessage('This is not a TIFF file.');
  103.     Dispose(nPics);
  104.     exit;
  105.   end;
  106.   width := (GetPixel(30,0)*256) + GetPixel(31,0);
  107.   height := (GetPixel(42,0)*256) + GetPixel(43,0);
  108.   Dispose(nPics);  {The ID of the last window opened is equal to nPics.}
  109.   offset:=768;
  110.   SetCustom(width,height,offset);
  111.   Import('');  {No prompt this time; Import remembers the name.}
  112. end;
  113.  
  114.  
  115. macro 'Import Multiple Images per File';
  116. {
  117. Imports a series of 256x256 images contained in a single file, in this
  118. case an NIH image stack with an arbitrary number of 256x256 slices.
  119. }
  120. var
  121.   offset,i,PicSize,HdrSize,width,height:integer;
  122. begin
  123.   HdrSize:= 768;
  124.   width:= 256;
  125.   height:=256;
  126.   PicSize:=width*height;
  127.   offset:=HdrSize;
  128.   SetImport('8-bit');
  129.   for I:=1 to 100 do begin  {Macro will terminate at eof}
  130.     SetCustom(width,height,offset);
  131.     Import('');
  132.     offset:=offset+PicSize;
  133.   end;
  134. end;
  135.